<script lang="ts" setup>
import { ref } from "vue";
import { Swiper, SwiperSlide } from "swiper/vue";
import { EffectCards } from "swiper/modules"; // 导入 Swiper 的模块
import { ImageAddHttp } from "@/utils/index"
import {advLike as advLikeApi} from "@/api/user"
import type { configType, userInfo as userInfoType } from "@/types/userInfo.d.ts"
const Props = defineProps<{ config: configType, userInfo:userInfoType }>()


const userInfo = ref<userInfoType>(Props.userInfo)

const advLike = async function(){
  const res = await advLikeApi()
  if(res.code){
    userInfo.value.score = res.data.score
  }
}

</script>
<template>

   <div class="friend-post">

    <div class="avatar_box">
      <img class="avatar" :src="ImageAddHttp(Props.config.adv_avatar)" alt="用户头像" />
    </div>
    <div class="content">
      <div class="name">{{Props.config.adv_name}}</div>
      <div class="text">{{Props.config.adv_post}}</div>
      <div class="banners">
        <!-- <img src="@/static/banner.png" alt="banner" /> -->
        <div class="swiper-container">
          <swiper
            :modules="[EffectCards]"
            loop
            effect="cards"
            :grabCursor="true" 
          >
            <swiper-slide v-for="(image, index) in Props.config.adv_images" :key="index">
              <img :src="ImageAddHttp(image)" :alt="'Slide ' + (index + 1)" />
            </swiper-slide>
          </swiper>
        </div>
      </div>
      <div class="footer">
        <div class="desc">{{Props.config.adv_desc}}</div>
        <div class="comment" @click="advLike">
          <!-- <img src="@/static/heart_icon.png" alt=""> -->
          <img :src="userInfo.score > 0 ? './src/static/heart_icon_active.png' : './src/static/heart_icon.png'" alt="">
          <span>{{userInfo.score > 0 ? userInfo.score : '点赞'}}</span>
        </div>
      </div>
    </div>
  </div>
</template>



<style lang="scss" scoped>
.swiper{
  overflow: visible !important;
}
.swiper-container {
  width: 100%;
  margin: 0 auto;
}
.swiper-slide {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
  height: 100%; /* 继承容器的高度 */
}

.swiper-slide img {
  width: 100%;
  height: auto;
  object-fit: contain; /* 保持图片比例缩放，防止溢出 */
}
.friend-post {
  padding: 16px;
  background: #fff;
  // border-radius: 8px;
  // box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  font-family: Arial, sans-serif;
  display: flex;
  // 横向排列
  flex-direction: row;

  .avatar_box{
    width: 54px;
    img{
      width: 54px;
      border-radius:4px
    }

  }
  .content {
    flex: 1;
    padding-left: 10px;
    width: 80%;
    .name {
      font-size: 1.2rem;
      font-weight: bold;
      color: #576B95 ;
    }
    .text {
      font-size: 0.9rem;
      color: #1A1A1A ;
      margin-top: 4px;
    }

    .banners {
      margin-top: 10px;
      width: 90%;
      position: relative;
      // img {
      //   width: 100%;
      //   border-radius: 4px;
      // }
      
    }
    .footer {
      margin-top: 10px;
      display: flex;
      justify-content: space-between;
      .desc {
        font-size: 0.8rem;
        color: #999;
      }
      .comment {
        display: flex;
        align-items: center;
        img {
          width: 16px;
          height: 16px;
        }
        span {
          font-size: 0.8rem;
          color: #666;
          margin-left: 5px;
        }
      }
    }
  }
}
</style>
